package com.hs.srm.api.modules.othersysapi.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hs.srm.admin.common.util.OANoticeUtil;
import com.hs.srm.common.utils.R;
import com.landray.kmss.km.review.webservice.Exception_Exception;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;

/**
 * @author socik
 * @date 2019/11/11 9:00
 * @email socik@qq.com
 */
@RestController
@RequestMapping("/api")
@Api(tags="OA信息通知接口")
@Validated
public class ToOaAPI {

    @ApiOperation(value="传入OA钉钉消息通知",notes = "根据账号和内容传入信息")
    @GetMapping("/sendMsg/{jsoncontext}")
    public R sendMsg(@ApiParam(value = "userId,context,docSubject:OA用户账号,OA传输内容,OA抬头描述") @PathVariable("jsoncontext")String jsonMsg) {
        JSONObject jsonObject= JSON.parseObject(jsonMsg);
        String userId=jsonObject.getString("userId");
        String context=jsonObject.getString("context");
        String docSubject=jsonObject.getString("docSubject");
        try {
            if(OANoticeUtil.sendMsg(userId,context,docSubject,true)){
                return R.msg("成功");
            }
        } catch (Exception_Exception e) {
            e.printStackTrace();
        }
        return R.msg("失败");
    }
}
